﻿var Normal_Lencene;
var Normal_LenceneStore;
// 功能模块grid展示
Normal_Lencene = function () {
    var url = "/manager/Normal_Lencene/List";


    //grid 填充
    Ext.define('Normal_LenceneGridModel', {
        extend: 'Ext.data.Model',
        fields: [
            { name: "Id", type: "string" },
            { name: "NextText", type: "string" },
            { name: "LastText", type: "string" }
            ]
    });

    //grid获取 json数组
    Normal_LenceneStore = Ext.create('Ext.data.Store', {
        pageSize: 100,
        model: 'Normal_LenceneGridModel',
        buffered: false,  //是否动态加载
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: url,
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        }
    });






    getUpdateNormal_LenceneInfo = function (pageIndex) {

        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在生成，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
        setTimeout(function () { }, 1000);
        var pageSize = 500;
        Ext.Ajax.timeout = 240000;
        Ext.Ajax.request({
            url: "/manager/Normal_Lencene/List",
            method: "get",
            params: {
                limit: pageSize,
                start: pageIndex
            },
            success: function (d) {
                Ext.MessageBox.hide();
                //成功后
                var action = Ext.JSON.decode(d.responseText);
                //alert(action.success);
                var count = action.totalPorperty;
                var message = action.message;
                Normal_LenceneStore.add({ "Id": pageIndex, "NextText": action.message });
                if (count > (pageIndex * pageSize)) {
                    pageIndex = pageIndex + 1;
                    getUpdateNormal_LenceneInfo(pageIndex);
                }
            },
            failure: function (form, action) {
                Ext.MessageBox.alert("提示!", "修改失败!");
            }
        })
    }

    //新增信息
    SaveNormal_LenceneFn = function () {
        Ext.Msg.confirm("提 示!", "确定后将删除全部索引，并重新索引，此过程根据数据大小决定时间长短，请不要随意关闭浏览器！！！", function (btn) {
            if (btn == "yes") {
                Normal_LenceneStore.removeAll();
                getUpdateNormal_LenceneInfo(1);

            }
        });
    }
    SaveNormal_LenceneGoFn = function () {
        textIndex = new Number(Ext.getCmp("textIndex").getValue())
        Ext.Msg.confirm("提 示!", "重新索引" + textIndex + "，此过程根据数据大小决定时间长短，请不要随意关闭浏览器！！！", function (btn) {
            if (btn == "yes") {
                Normal_LenceneStore.removeAll();
                getUpdateNormal_LenceneInfo(textIndex);

            }
        });
    }

    getUpdateNormal_LenceneInfo2 = function (pageIndex) {

        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在生成，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
        setTimeout(function () { }, 1000);
        var pageSize = 500;
        Ext.Ajax.timeout = 240000;
        Ext.Ajax.request({
            url: "/manager/Normal_Lencene/List2",
            method: "get",
            params: {
                limit: pageSize,
                start: pageIndex
            },
            success: function (d) {
                Ext.MessageBox.hide();
                //成功后
                var action = Ext.JSON.decode(d.responseText);
                //alert(action.success);
                var count = action.totalPorperty;
                var message = action.message;
                Normal_LenceneStore.add({ "Id": pageIndex, "NextText": action.message });
                if (count > (pageIndex * pageSize)) {
                    pageIndex = pageIndex + 1;
                    getUpdateNormal_LenceneInfo2(pageIndex);
                }
            },
            failure: function (form, action) {
                Ext.MessageBox.alert("提示!", "修改失败!");
            }
        })
    }

    SaveNormal_LenceneFn2 = function () {
        Ext.Msg.confirm("提 示!", "确定后将删除全部索引，并重新索引，此过程根据数据大小决定时间长短，请不要随意关闭浏览器！！！", function (btn) {
            if (btn == "yes") {
                Normal_LenceneStore.removeAll();
                var abc = Ext.getCmp("searchIndex").getValue();
                if (abc != "")
                    searchIndex = new Number(abc)
                else
                    searchIndex = 1;

                getUpdateNormal_LenceneInfo2(searchIndex);

            }
        });
    }

    var OptimizeNormal_LenceneFn = function () {
        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在优化，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
        setTimeout(function () { }, 1000);
        var pageSize = 1000;
        Ext.Ajax.request({
            url: "/manager/Normal_Lencene/Update",
            method: "get",
            success: function (d) {
                Ext.MessageBox.hide();
                //成功后
                var action = Ext.JSON.decode(d.responseText);
                Normal_LenceneStore.add({ "Id": action.success, "NextText": action.message });
                if (count > (pageIndex * pageSize)) {
                    pageIndex = pageIndex + 1;
                    getUpdateNormal_LenceneInfo(pageIndex);
                }
            },
            failure: function (form, action) {
                Ext.MessageBox.alert("提示!", "优化失败!");
            }
        })

    }

    //grid配置
    var grid = Ext.create('Ext.grid.Panel', {
        id: "Normal_LencenePanel",
        renderTo: "Normal_LenceneGrid",
        layout: "fit",
        alias: 'widget.methodPanel',
        columnLines: true,
        loadMask: true,
        frame: true,
        border: false,
        autoScroll: true,
        store: Normal_LenceneStore,
        columnLines: true,
        //cm: cm2,
        viewConfig: {
            stripeRows: true,
            trackOver: true,
            emptyText: '<div style="color:#999;margin:5px;">当前没有记录显示<div>'
        },
        stripeRows: true,
        tbar: [            		 //工具条设置
            		 {
            		 text: "全部重新索引",
            		 tooltip: "全部重新索引",
            		 iconCls: "addicon",
            		 handler: SaveNormal_LenceneFn
           }, "", "-", "", {
               text: "开始索引从",
               tooltip: "开始索引从",
               iconCls: "addicon",
               handler: SaveNormal_LenceneGoFn
           }, "-", {
               xtype: 'textfield',
               name: 'textIndex',
               id: 'textIndex',
               emptyText: '输入开始索引值'
           }, "", {
               text: "搜索重新索引",
               tooltip: "搜索重新索引",
               iconCls: "addicon",
               handler: SaveNormal_LenceneFn2
           }, "-", {
               xtype: 'textfield',
               name: 'searchIndex',
               id: 'searchIndex',
               emptyText: '输入开始索引值'
           }, "", {
       }, "", "-", "", {
           text: "优化索引",
           tooltip: "优化索引，优化索引时硬盘压力比较大，重新索引后会自动优化，不必经常优化。",
           iconCls: "editicon",
           handler: OptimizeNormal_LenceneFn
       }, "-"],
        columns: [
               Ext.create('Ext.grid.RowNumberer'),
                { header: "编号", dataIndex: "Id", width: 80, sortable: true },
                { header: "提示", dataIndex: "NextText", width: 500, sortable: true }
                  ]
    });


}
    Normal_Lencene();
